home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODF-Interest Archive / May 96 / Re CyberItems and FW_CWritable < prev    next >
Encoding:
Internet Message Format  |  1996-12-03  |  3.6 KB  |  [TEXT/ttxt]

  1. Subject:     Re: CyberItems and FW_CWritable/ReadableStream
  2. Sent:        5/11/96 1:52 PM
  3. Received:    5/17/96 9:02 AM
  4. From:        Mark Lanett, mlanett@meer.net
  5. Reply-To:    ODF-Interest@CILabs.ORG
  6. To:          OpenDoc Development Framework Discussion List, ODF-Interest@CILabs.
  7.  
  8. >It's been noted that ODF 1.0 has Cyberdog support. I ran into a little
  9. >problem this evening with d11, and wonder if 1.0 has a good solution to
  10. >it...
  11.  
  12. First off, the stuff in ODF R1 is pretty rudimentary. We'll be putting
  13. updates on our web site with bug fixes and lots more features. It'll be
  14. announced in a week or so (after WWDC).
  15.  
  16. Second, regarding streaming in general: you don't want to go getting the
  17. StorageUnit from a sink. While today you are almost always dealing with a
  18. StorageUnitSink, which has a StorageUnit behind it, this won't always be
  19. the case. For instance, ODF R1 has a BufferSink which sits on top of
  20. StorageUnitSinks, and Real Soon Now you'll also be using a CyberStreamSink.
  21. If you must get the sink, at least use runtime dynamic casting.
  22.  
  23. Thirdly, about streaming cyberitems:
  24.  
  25. Actually CyberItem *does* have an unflatten method. This solves most
  26. problems, except that you need to instantiate a CyberItem before you can
  27. unflatten it, which means you need to know the classname. Fortunately the
  28. classname is part of the flattened cyberitem data. I'm not worried about
  29. the format changing -- since it has a version number, that can be dealt
  30. with.
  31.  
  32. These routines work with R1, but you can probably use them under d11 with
  33. few or no problems.
  34.  
  35. /*
  36.         Utilities for getting CyberItems into and out of ODF streams.
  37.  
  38.         Format of a CyberItem:
  39.  
  40.         long    length          (includes this field)
  41.         short   signature       ('cy')
  42.         short   version
  43.         long    classid length
  44.         N               classid
  45.         <private data>
  46. */
  47.  
  48. void FW_WriteCyberItem (Environment* ev, CyberItem* ci, FW_OSink* sink)
  49. {
  50.         long size = ci->GetFlatSize(ev);
  51.         TempODPtr tbuffer = new char[size];
  52.         char* buffer = (char*) (void*) tbuffer;
  53.         size = ci->Flatten (ev, buffer, size);
  54.         sink->Write (ev, buffer, size);
  55. }
  56.  
  57. CyberItem* FW_ReadCyberItem (Environment* ev, CyberSession* session,
  58. FW_OSink* sink)
  59. {
  60.         // First we read in the classname to create the CyberItem
  61.         FW_CReadableStream header (sink);
  62.         long size, classsize;
  63.         short signature, version;
  64.         header >> size >> signature >> version >> classsize;
  65.         if (signature != 'cy')
  66.                 FW_Failure (FW_xCorruptArchiveStream);
  67.         TempODPtr tclassname = new char [classsize+1];
  68.         char* classname = (char*) (void*) tclassname;
  69.         header.Read (classname, classsize);
  70.         classname[classsize] = 0;
  71.  
  72.         // Create a buffer with the CyberItem header and data
  73.         TempODPtr tbuffer = new char[size];
  74.         char* buffer = (char*) (void*) tbuffer;
  75.         FW_PMemorySink copysink (ev, buffer, size, 0);
  76.         FW_CWritableStream copy (copysink);
  77.         copy << size << signature << version << classsize;
  78.         copy.Write (classname, classsize);
  79.         long offset = copysink->GetPosition(ev);
  80.         sink->Read (ev, buffer + offset, size - offset);
  81.  
  82.         // Finally create the CyberItem and read it from the memory buffer.
  83.         CyberItem* ci = session->NewCyberItem (ev, classname);
  84.         FW_TRY
  85.                 ci->ICyberItem (ev);
  86.                 ci->Unflatten (ev, buffer);
  87.         FW_CATCH_BEGIN
  88.         FW_CATCH_EVERYTHING() {
  89.                 delete ci;
  90.                 FW_THROW_SAME();
  91.         }
  92.         FW_CATCH_END
  93.  
  94.         return ci;
  95. }
  96.  
  97.  
  98. --
  99. Mark Lanett <mlanett@meer.net>
  100. Have a bajillion brilliant Jobsian lithium licks
  101.  
  102.